
//
//  PersonTaskController.m
//  PASystem
//
//  Created by 刘沿 on 16/9/23.
//  Copyright © 2016年 czd. All rights reserved.
//

#import "PersonTaskController.h"
#import "PersonTaskModel.h"
#import "UILabel+time.h"
@interface PersonTaskController ()
@property (nonatomic,strong) UITableView *tab;
@property (nonatomic,strong) NSMutableArray *dataArray;
@end

@implementation PersonTaskController

static NSString *reuseID = @"PersonTaskCell";

-(NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithRed:241/255.0 green:242/255.0 blue:243/255.0 alpha:1];
    

    [self loadData];
    
}

- (void)loadData{
    
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];
    NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];
    
    NSString *json = [NSString stringWithFormat:@"{'action': mywsdxMch,'service': PartydeptService, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@}'}",userId,pwdId,userHumber,self.ID];
    
    NSArray * array = @[@{@"arg0":json}];
    
    
    [HttpTools requestWithURL:BaseURL arrays:array method:Basemethod success:^(id JSON) {
        [self.dataArray removeAllObjects];
       
        NSDictionary *dict = JSON[@"reason"];
        if (dict) {
            
            NSDictionary *dict2 = dict[@"attrs"];
            PersonTaskModel *model = [PersonTaskModel mj_objectWithKeyValues:dict2];
            
            [self.dataArray addObject:model];
        }
        
        [self setUPKind:self.dataArray];
        
        [self.tab reloadData];
        [self.tab headerEndRefreshing];
    } failure:^(NSError *error) {
        
        
    }];
    
}

//设置页面
- (void)setUPKind:(NSMutableArray *)arr{
    //上半部分的View
    UIView *topView = [[UIView alloc] init];
    topView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).mas_offset(10);
        make.left.equalTo(self.view.mas_left).mas_offset(10);
        make.right.equalTo(self.view.mas_right).mas_offset(-10);
        make.height.equalTo(@250);
    }];
    
    PersonTaskModel *model = self.dataArray.firstObject;
    //标题
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.font = [UIFont systemFontOfSize:17];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = model.TITLE;
    [topView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topView.mas_top).mas_offset(10);
        make.left.equalTo(topView.mas_left);
        make.right.equalTo(topView.mas_right);
        make.height.equalTo(@30);
    }];
    //作者
    UILabel *author = [[UILabel alloc] init];
    author.text = @"发表人：";
    [topView addSubview:author];
    author.font = [UIFont systemFontOfSize:14];
    [author mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topView.mas_top).mas_offset(45);
        make.left.equalTo(topView.mas_left).mas_offset(10);
    }];
    
    UILabel *AUlbl = [[UILabel alloc] init];
    AUlbl.font = [UIFont systemFontOfSize:14];
    [topView addSubview:AUlbl];
    AUlbl.text = model.USERNAME;
    [AUlbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(author.mas_centerY);
        make.left.equalTo(author.mas_right).mas_offset(5);
    }];
    
    //时间
    UILabel *time = [[UILabel alloc] init];
    time.text = @"发表时间：";
    [topView addSubview:time];
    time.font = [UIFont systemFontOfSize:14];
    [time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(AUlbl.mas_centerY);
        make.left.equalTo(AUlbl.mas_right).mas_offset(10);
    }];
    
    UILabel *timelbl = [[UILabel alloc] init];
    timelbl.font = [UIFont systemFontOfSize:14];
    [topView addSubview:timelbl];
    NSString *str = [UILabel withTimeStr:model.CREATETIME];
    timelbl.text = str;
    [timelbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(time.mas_centerY);
        make.left.equalTo(time.mas_right).mas_offset(5);
        
    }];
    
    //赞
    UIImageView *imageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"赞"]];
    [topView addSubview:imageV];
    [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topView.mas_top).mas_offset(45);
        make.right.equalTo(topView.mas_right).mas_offset(-50);
        make.width.equalTo(@15);
        make.height.equalTo(@15);
    }];
    
    UILabel *lbl = [[UILabel alloc] init];
    lbl.font = [UIFont systemFontOfSize:14];
    lbl.text = [NSString stringWithFormat:@"赞(%@)",model.COUNTDZ];
    [topView addSubview:lbl];
    [lbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(imageV.mas_centerY);
        make.right.equalTo(topView.mas_right).mas_offset(-5);
        make.left.equalTo(imageV.mas_right).mas_offset(5);
    }];
    
    //线
    UIView *lineview = [[UIView alloc] init];
    lineview.backgroundColor = [UIColor lightGrayColor];
    [topView addSubview:lineview];
    [lineview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lbl.mas_bottom).mas_offset(5);
        make.left.equalTo(topView.mas_left).mas_offset(5);
        make.right.equalTo(topView.mas_right).mas_offset(-5);
        make.height.equalTo(@1);
    }];
    
    //web
    UIWebView *web = [[UIWebView alloc] init];
    [topView addSubview:web];
    [web mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lineview.mas_top).mas_offset(10);
        make.left.equalTo(topView.mas_left).mas_offset(10);
        make.right.equalTo(topView.mas_right).mas_offset(-10);
        make.bottom.equalTo(topView.mas_bottom).mas_offset(-10);
    }];
    
    //展会内容
    NSString *str3 = [model.CONTENT stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
    
    NSString *str2 = [str3 stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];

    
    [web loadHTMLString:str2 baseURL:nil];
    
//下半部分
    UIView *bottomVi = [[UIView alloc] init];
    bottomVi.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bottomVi];
    [bottomVi mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topView.mas_bottom).mas_offset(10);
        make.left.equalTo(self.view.mas_left).mas_offset(10);
        make.right.equalTo(self.view.mas_right).mas_offset(-10);
        make.bottom.equalTo(self.view.mas_bottom).mas_offset(-60);
    }];
    
    UIView *colorV = [[UIView alloc] init];
    [bottomVi addSubview:colorV];
    colorV.backgroundColor = [UIColor blueColor];
    [colorV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bottomVi.mas_top).mas_offset(10);
        make.left.equalTo(bottomVi.mas_left).mas_offset(10);
        make.width.equalTo(@4);
        make.height.equalTo(@20);
    }];
    
    UILabel *Lbl = [[UILabel alloc] init];
    Lbl.text = @"学习反馈";
    [bottomVi addSubview:Lbl];
    [Lbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(colorV.mas_centerY);
        make.left.equalTo(colorV.mas_right).mas_offset(5);
    }];
    
    UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"user"]];
    
    [bottomVi addSubview:image];
    
    [image mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(colorV.mas_bottom).mas_offset(10);
        make.left.equalTo(bottomVi.mas_left).mas_offset(10);
        make.width.equalTo(@30);
        make.height.equalTo(@30);
    }];
    
    UILabel *nameL = [[UILabel alloc] init];
    nameL.text = model.USERNAME;
    [bottomVi addSubview:nameL];
    [nameL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(image.mas_centerY);
        make.left.equalTo(image.mas_right).mas_offset(5);
    }];
    
    UILabel *tiLabel = [[UILabel alloc] init];
    NSString *strt = [UILabel withTimeStr:model.CREATETIME];
    tiLabel.text = strt;
    [bottomVi addSubview:tiLabel];
    [tiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(image.mas_centerY);
        make.right.equalTo(bottomVi.mas_right);
    }];
    
    UIWebView *botweb = [[UIWebView alloc] init];
    [bottomVi addSubview:botweb];
    [botweb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(image.mas_bottom).mas_offset(10);
        make.left.equalTo(bottomVi.mas_left).mas_offset(10);
        make.right.equalTo(bottomVi.mas_right).mas_offset(-10);
        make.bottom.equalTo(bottomVi.mas_bottom).mas_offset(-10);
    }];
    
    NSString *strtt = [model.FEEDBACKCONTENT stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
    
    NSString *str2t = [strtt stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];
    
    
    [botweb loadHTMLString:str2t baseURL:nil];

    
}







@end












